package com.Practice.Student;

import java.util.Objects;

public class Student {
    private final long id;
    private final String name;
    private final int age;

    // 构造函数
    public Student(long id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    // 重写toString方法
    @Override
    public String toString() {
        return "学号：" + id + "，姓名：" + name + "，年龄：" + age;
    }

    // 重写equals方法
    @Override
    public boolean equals(Object obj) {
        // 1. 检查是否是同一个对象引用
        if (this == obj) return true;

        // 2. 检查对象是否为null或类型不同
        if (obj == null || getClass() != obj.getClass()) return false;

        // 3. 类型转换
        Student student = (Student) obj;

        // 4. 比较所有关键字段
        return id == student.id &&
                age == student.age &&
                Objects.equals(name, student.name);
    }

    // 重写hashCode方法
    @Override
    public int hashCode() {
        return Objects.hash(id, name, age);
    }
}

